<?php

namespace app\admin\controller;

use  app\common\controller\Admin;

class Novel extends Admin
{
    public function _initialize()
    {
        parent::_initialize();
        $this->getContentMenu();
        $this->model_id = $model_id = 1;
        $list = db('Model')->column('*', 'id');

        if (empty($list[$model_id])) {
            return $this->error("无此模型！");
        } else {
            $this->modelInfo = $list[$model_id];
            $this->model = M($this->modelInfo['name']);
        }

        $this->assign('model_id', $model_id);
        $this->assign('model_list', $list);
    }

    /**
     * Notes:内容列表
     * @return mixed|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author: Zhu
     * @since: 2023/1/9 9:36
     */
    public function index()
    {
        if ($this->modelInfo['list_grid'] == '') {
            return $this->error("列表定义不正确！", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
        }

        $allvisit = input('allvisit');
        $is_new = input('is_new');
        $is_free = input('is_free');
        $is_old = input('is_old');
        $is_license = input('is_license');
        $is_recommend = input('is_recommend');
        $index = input('index');
        $update = input('update');
        $chapters = input('chapters');
        $siteid = input('siteid', -1);

        $order = '';

        if ($is_new) {
            $order .= "create_time DESC,";
        } elseif ($is_license) {
            $order .= "top DESC,";
        }

        $order .= "allvisit asc,id desc";
        $grid_list = get_grid_list($this->modelInfo['list_grid']);
        //$order     = "id desc";
        $map = $this->buildMap();
        $field = array_filter($grid_list['fields']);

        if ($is_free) {
            $articleid = db('limitedfree')->where('enddate >' . time())->order('create_time DESC')->limit(1)->value('articleid');
            $map['id'] = ['in', $articleid];
        }

        if ($is_new) {
            $map['create_time'] = array("<", "now() + interval 7 day");
        }

        //派单指数
        if ($index == 1) {
            $map['index'] = array(array(">=", 91), array("<", 100));
        } elseif ($index == 2) {
            $map['index'] = array(array(">=", 76), array("<=", 90));
        } elseif ($index == 3) {
            $map['index'] = array(array(">=", 61), array("<=", 75));
        } elseif ($index == 4) {
            $map['index'] = array(array(">=", 51), array("<=", 60));
        } elseif ($index == 5) {
            $map['index'] = array(array(">=", 1), array("<=", 50));
        } elseif ($index == 6) {
            $map['index'] = 0;
        }

        //上架时间
        if ($update == 1) {
            $starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
            $endtime = mktime(23, 59, 59, date('m'), date('d'), date('Y'));
            $map['create_time'] = [[">=", $starttime], ["<=", $endtime]];
        } elseif ($update == 2) {
            $starttime = mktime(0, 0, 0, date('m'), date('d') - 7, date('Y'));
            $endtime = mktime(23, 59, 59, date('m'), date('d'), date('Y'));
            $map['create_time'] = [[">=", $starttime], ["<=", $endtime]];
        } elseif ($update == 3) {
            $starttime = mktime(0, 0, 0, date('m'), 1, date('Y'));
            $endtime = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
            $map['create_time'] = [[">=", $starttime], ["<=", $endtime]];
        }

        //小说章节
        if ($chapters == 1) {
            $map['chapters'] = array(array(">=", 0), array("<", 100));
        } elseif ($chapters == 2) {
            $map['chapters'] = array(array(">=", 100), array("<", 300));
        } elseif ($chapters == 3) {
            $map['chapters'] = array(array(">=", 300), array("<", 600));
        } elseif ($chapters == 4) {
            $map['chapters'] = array(">=", 600);
        }

        if ((int)$siteid > -1) {
            $map['siteid'] = $siteid;
        }
        if (isset($map['siteid']) && $map['siteid'] == -1) {
            unset($map['siteid']);
        }

        if ($is_recommend) {
            $map[''] = ['exp', 'FIND_IN_SET(9,is_top)'];
        }

        if ($is_old) {
            $map[''] = ['exp', 'FIND_IN_SET(10,is_top)'];
        }

        if (session('user_auth.group') != 999) {
            $map['status'] = 1;
        }

        $list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row'], false, ['query' => ['is_new' => input('is_new'), 'status' => input('status'), 'channel' => input('channel'), 'category_id' => input('category_id'), 'update' => input('update'), 'fullflag' => input('fullflag'), 'index' => input('index'), 'chapters' => input('chapters'), 'siteid' => input('siteid'), 'allvisit' => $allvisit]]);
        $catemap = [];
        $catemap['model_id'] = 1;
        //读者性别
        if (input('channel') == 1) {
            $catemap['name'] = "男频";
        }
        if (input('channel') == 2) {
            $catemap['name'] = "女频";
        }


        $category = db('category')->where($catemap)->select();

        $sourceidmap = [];
        if (input('siteid') > 0) {
            $sourceidmap['siteid'] = input('siteid');
        } else {
            $sourceidmap['siteid'] = -1;
        }

        $sourceid = db('third_novel')->where($sourceidmap)->select();

        //获取授权用户组
        $access = config('cartoon_access');
        //获取当前用户组
        $group = session('user_auth.group');

        $novel = db('novel')->where('status = 1')->field('id,title as name')->select();
        //获取默认章节售价配置信息
        $saleprice = db('config')->where(array('name' => 'chaptersaleprice'))->field("extra")->cache(true)->find();
        $chaptersaleprice = parse_field_attr($saleprice["extra"]);
        //获取默认千字售价配置信息
        $wordsperegold = db('config')->where(array('name' => 'wordsperegold'))->field("extra")->cache(true)->find();
        $wordsperegold = parse_field_attr($wordsperegold["extra"]);

        $data = array(
            'grid' => $grid_list,
            'list' => $list,
            'novel' => $novel,
            'page' => $list->render(),
            'group' => $group,
            'is_new' => input('is_new'),
            'is_old' => input('is_old'),
            'is_free' => input('is_free'),
            'is_license' => input('is_license'),
            'is_recommend' => input('is_recommend'),
            'index' => $index,
            'update' => $update,
            'chapters' => $chapters,
            'status' => input('status'),
            'channel' => input('channel'),
            'fullflag' => input('fullflag'),
            'category' => $category,
            'category_id' => input('category_id'),
            'access' => $access,
            'chaptersaleprice' => $chaptersaleprice,
            'wordsperegold' => $wordsperegold,
            'allvisit' => $allvisit,
            'cp_member' => getCpsCpMember(-1),
            'siteid' => $siteid,
            'sourceid' => $sourceid
        );
        if ($this->modelInfo['template_list']) {
            $template = 'content/' . $this->modelInfo['template_list'];
        }
        $this->assign($data);
        $this->setMeta($this->modelInfo['title'] . "列表");
        return $this->fetch($template);
    }

    /**
     * Notes:创建搜索
     * @return array
     * @since: 2023/1/9 9:36
     * @author: Zhu
     */
    protected function buildMap()
    {
        $map = array();
        $data = $this->request->param();
        foreach ($data as $key => $value) {
            if ($value) {
                if ($key == 'keyword') {
                    $map['title|author'] = array("LIKE", "%$value%");
                } elseif ($key == 'category') {
                    $map['category_id'] = $value;
                } elseif ($key == 'create_time') {
                    $map['create_time'] = array('BETWEEN', array(strtotime($value[0]), strtotime($value[1])));
                } elseif ($key == 'fullflag') {
                    $map['fullflag'] = $value == 1 ? 1 : 0;
                } elseif ($key == 'is_new' || $key == 'allvisit' || $key == 'is_free' || $key == 'is_license' || $key == 'is_recommend' || $key == 'is_old' || $key == 'update' || $key == 'is_index' || $key == 'chapters') {

                } else {
                    $map[$key] = $value;
                }
            }
        }
        if (isset($map['page'])) {
            unset($map['page']);
        }

        if (isset($map['model_id'])) {
            unset($map['model_id']);
        }
        $this->assign($data);
        return $map;
    }

    /**
     * Notes: 新增
     * @return mixed|null
     * @since: 2023/1/9 9:36
     * @author: Zhu
     */
    public function add()
    {
        if (IS_POST) {
            $this->param['uid'] = session('user_auth.uid');
            $result = $this->model->save($this->param);
            if ($result) {
                //记录行为
                action_log('add_content', 'content', $result, session('user_auth.uid'));
                return $this->success("添加成功！", url('admin/novel/index', array('model_id' => $this->modelInfo['id'])));
            } else {
                return $this->error($this->model->getError(), url('admin/novel/add', array('model_id' => $this->modelInfo['id'])));
            }
        } else {
            $info = array(
                'model_id' => $this->modelInfo['id'],
            );
            $data = array(
                'info' => $info,
                'fieldGroup' => $this->getField($this->modelInfo),
            );

            if ($this->modelInfo['template_add']) {
                $template = 'content/' . $this->modelInfo['template_add'];
            } else {
                $template = 'novel/edit';
            }
            $this->assign($data);
            $this->setMeta("添加" . $this->modelInfo['title']);
            return $this->fetch($template);
        }
    }

    /**
     * Notes: 获取字段信息
     * @return array
     * @since: 2023/1/9 9:36
     * @author: Zhu
     */
    protected function getField()
    {
        $field_group = parse_config_attr($this->modelInfo['attribute_group']);
        $map['model_id'] = $this->modelInfo['id'];
        if ($this->request->action() == 'add') {
            $map['is_show'] = array('in', array('1', '2'));
        } elseif ($this->request->action() == 'edit') {
            $map['is_show'] = array('in', array('1', '3'));
        }

        //获得数组的第一条数组
        $rows = model('Attribute')->getFieldlist($map, 'id');
        if (!empty($rows)) {
            foreach ($rows as $key => $value) {
                $list[$value['group_id']][] = $value;
            }
            foreach ($field_group as $key => $value) {
                $fields[$value] = isset($list[$key]) ? $list[$key] : array();
            }
        } else {
            $fields = array();
        }
        return $fields;
    }

    /**
     * Notes: 删除
     * @return null
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     * @since: 2023/1/9 9:36
     * @author: Zhu
     */
    public function del()
    {
        $id = $this->getArrayParam('id');
        if (empty($id)) {
            return $this->error("非法操作！");
        }

        $map['id'] = array('IN', $id);

        $result = $this->model->where($map)->delete();

        if (false !== $result) {
            $chapterid = db('chapter')->where(['articleid' => array('IN', $id)])->column('id');
            //删除章节
            db('chapter')->where(['articleid' => array('IN', $id)])->delete();
            //删除章节内容
            db('novel_content')->where(['chapterid' => array('IN', implode(',', $chapterid))])->delete();

            //记录行为
            action_log('delete_novel', 'novel', $result, session('user_auth.uid'));
            return $this->success("删除成功！");
        } else {
            return $this->error("删除失败！");
        }
    }

    /**
     * Notes: 上传小说
     * @return mixed|null
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     * @author: Zhu
     * @since: 2023/1/9 9:54
     */
    public function uploadbook()
    {

        if (IS_POST) {
            $ebook = input('post.ebook');

            if (empty($ebook)) {
                return $this->error("电子书不能为空");
            }

            if (empty($this->param["category_id"])) {
                return $this->error("小说分类不能为空");
            }

            if (empty($this->param["title"])) {
                return $this->error("小说名字不能为空");
            }

            //小说存在
            $articleinfo = db('novel')->where('title', 'like', '%' . $this->param["title"] . '%')->value('id');

            if ($articleinfo) {
                $articleid = $articleinfo;
                $chapters = db('novel')->where('title', 'like', '%' . $this->param["title"] . '%')->value('chapters');
            } else {//不存在
                $this->param['create_time'] = time();
                $this->param['update_time'] = time();
                unset($this->param['id']);
                $result = $this->model->save($this->param);
                $articleid = $this->model->getLastInsID();
                $chapters = 0;
            }

            //增加章节
            if ($articleid) {
                $info = db('novel')->where("id", $articleid)->find();

                $bookList = $this->readList($ebook);
                $i = $chapters?$chapters:1;
                $size=$monthupds=$premonthsize =$premonthupds= 0;
                foreach ($bookList as $k => $v) {
                    $chapterdata['articleid'] = $articleid;
                    $chapterdata['uid'] = session("user_auth.uid");
                    $chapterdata['chaptername'] = $v["name"];
                    //$chapterdata['content'] = $v["content"];
                    $chapterdata['create_time'] = time();
                    $chapterdata['update_time'] = time();
                    $chapterdata['size'] = get_count_content($v['content']);
                    $chapterdata['saleprice'] = round($chapterdata['size'] / 1000 * config('wordsperegold'));
                    if ($i > 20) {
                        $chapterdata['isvip'] = 1;
                        $chapterdata['saleprice'] = round($chapterdata['size'] / 1000 * config('wordsperegold'));
                    }

                    $chapterdata['chapterorder'] = $i;
                    $chapterdata['articlename'] = $this->param['title'];
                    db('chapter')->insert($chapterdata);

                    $chapterId = db('chapter')->getLastInsID();

                    //更新小说章节内容
                    $ocontent['chapterid'] = $chapterId;
                    //$ocontent['content'] = "<p>".str_replace(array("\r\n", "\r", "\n"),'</p><p>',$v["content"])."</p>";
                    $ocontent['content'] = $this->format_content($v["content"]);
                    //数据分表开启的时候
                    if (config('partition')) {
                        $rule = [
                            'type' => 'mod', // 分表方式
                            'num' => 10     // 分表数量
                        ];
                        db("novel_content")->partition(['chapterid' => $chapterId], "chapterid", $rule)->insert($ocontent);
                    } else {
                        db("novel_content")->insert($ocontent);
                    }

                    //更新小说章节最新信息
                    db('novel')->where(array('id' => $articleid))->update(array('lastvolumeid' => $chapterId, 'lastvolume' => $v["name"]));

                    $size += $chapterdata['size'];
                    $i++;
                }
                //更新小说总字数
                $addorup = visit_addorup($info['update_time']);
                $monthsize = $addorup['month'] ? $size : ($info['monthsize'] + $size);
                if (1 < $addorup['month']) {
                    $premonthsize = 0;
                    $premonthupds = 0;
                    $monthupds = 0;
                }
                else if ($addorup['month'] == 1) {
                    $premonthsize = $info['monthsize'];
                    $premonthupds = $info['monthupds'];
                    $monthupds = 0;
                }

                if ($addorup['day']) {
                    $monthupds = $info['monthupds'] + 1;
                }
                db('novel')->where(array('id' => $articleid))->update(array('chapters' => $i, 'update_time' => time(), 'size' => array('exp', '`size`+' . $size), 'monthsize' => $monthsize, 'premonthsize' => $premonthsize, 'monthupds' => $monthupds, 'premonthupds' => $premonthupds));
            }
            //记录行为
            action_log('add_content', 'content', $result, session('user_auth.uid'));
            return $this->success("添加成功！", url('admin/novel/index', array('model_id' => $this->modelInfo['id'])));
        } else {
            $info = array(
                'model_id' => $this->modelInfo['id'],
            );
            $data = array(
                'info' => $info,
                'fieldGroup' => $this->getField($this->modelInfo),
            );
            $this->assign($data);
            $this->setMeta("上传小说");
            return $this->fetch();
        }
    }

    public function readList($file) {
        $list = array();
        $content =file_get_contents($file);
        //增加识别文本编码 2019.03.14
        $encode = mb_detect_encoding($content,array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
        $content = $this->clearContent($content,$encode);

        $content = preg_replace('/\n(?:(?:VIP|最新|防采集|网友上传)\s*(?:卷|分卷|章节)|正文|作品相关)\s*/i', "\n", $content);

        $jieqiConfigs=[
            'article'=>[
                'minwords'=>0,
                'maxwords'=>10000000,
                'splitwords'=>10000000
            ]
        ];
        if (preg_match_all('/\n.{0,20}(第(?:一|二|三|四|五|六|七|八|九|十|百|千|万|两|壹|廿|卅|卌|零|〇|１|２|３|４|５|６|７|８|９|０|①|⑴|㈠|[0-9])+(?:章|节|回).{0,50})\n/', $content, $match, PREG_OFFSET_CAPTURE) || preg_match_all('/\n((?:d|第|弟|递|滴|低|地|底|帝|的)*(?:一|二|三|四|五|六|七|八|九|十|百|千|万|两|壹|廿|卅|卌|零|〇|１|２|３|４|５|６|７|８|９|０|①|⑴|㈠|[0-9])+(?:部|卷|集|篇|册|章|节|回).{0,50})\n/', $content, $match, PREG_OFFSET_CAPTURE)) {
            if ($match[0][0][1] > 1000) {
                array_unshift($match[0], array('作品相关', -8));
                array_unshift($match[1], array('作品相关', -8));
            }
            $c = 0;

            foreach ($match[1] as $key => $val) {
                $start = $match[0][$key][1] + strlen($match[0][$key][0]);
                $end = isset($match[0][$key + 1]) ? $match[0][$key + 1][1] : strlen($content);
                $chapter = $this->splitword(substr($content, $start, $end - $start), $jieqiConfigs['article']['minwords'], $jieqiConfigs['article']['maxwords']);
                if (is_array($chapter)) {
                    foreach ($chapter as $k => $v) {
                        $list[$c] = array('name' => trim($val[0])." (".($k+1).")", 'size' => strlen($v), 'content' => "    ".str_replace("\n", "\r\n\r\n    ", $v));
                        $c++;
                    }
                } else {
                    if (empty($chapter)) continue;
                    $list[$c] = array('name' => trim($val[0]), 'size' => $end - $start, 'content' => "    ".str_replace("\n", "\r\n\r\n    ", $chapter));
                    $c++;
                }
            }
        } else {
            $chapter = $this->splitword($content, 0, $jieqiConfigs['article']['splitwords']);
            if (!empty($chapter)) {
                $chapter = is_array($chapter) ? $chapter : array($chapter);
                foreach ($chapter as $key => $val) {
                    $list[] = array('name' => "第 ".($key+1)." 章节", 'size' => strlen($val), 'content' => "    ".str_replace("\n", "\r\n\r\n    ", $val));
                }
            }
        }
        return $list;
    }

    protected function clearContent($string,$encode='') {
        if($encode !='UTF-8'){
            //$string = iconv('GBK', 'UTF-8//IGNORE', $string);
            $string = mb_convert_encoding($string, "UTF-8", $encode);
        }

        $string = str_replace("\t", ' ', $string);
        $string = str_replace("\r", "\n", $string);
        $string = $this->replacePlus('\\', '', $string);
        $string = $this->replacePlus('　', ' ', $string);
        $string = $this->replacePlus('；', ";\r", $string);
        while(stripos($string, '&amp;') !== false) {
            $string = str_ireplace('&amp;', '&', $string);
        }
        $string = str_ireplace(array('&#38;', '&amp', 'amp;'), '&', $string);
        $string = preg_replace(array('/&(apos|#39);/i', '/&(quot|#34);/i', '/&(nbsp|#160);/i', '/&(lt|#60);/i', '/&(gt|#62);/i'), array("'", '"', ' ', '<', '>'), $string);
        $string = html_entity_decode($string, ENT_QUOTES, 'GB2312');
        $string = str_ireplace(array('&apos', 'apos;', 'apos', '&quot', 'quot;', 'quot', '&nbsp', 'nbsp;', 'nbsp', '&lt', 'lt;', '&gt', 'gt;'), array("'", "'", "'", '"', '"', '"', ' ', ' ', ' ', '<', '<', '>', '>'), $string);
        $string = preg_replace('/&#?[a-zA-Z0-9]+;/', '', $string);
        $string = str_replace(";\r", '；', $string);
        $string = str_replace("\r", '', $string);
        $string = preg_replace('/<br[\s\/]*>/i', "\n", $string);
        $string = preg_replace('/<\/?p>/i', "\n", $string);
        $string = preg_replace('/<!--.*?-->|<\?|\?>|<%|%>|<@|@>/', '', $string);
        $string = preg_replace('/<(script|style).*\/\1>/is', '', $string);
        $string = preg_replace('/<\/?(?:html|head|meta|link|base|basefont|body|bgsound|title|style|script|noscript|object|form|select|option|iframe|frame|frameset|applet|button|code|event|id|input|ilayer|layer|name|xml|userprofile|table|tbody|thead|tfoot|th|tr|td|i|b|u|strong|img|p|br|div|em|ul|ol|li|dl|dd|dt|a|font|span|embed|hr|blockquote|h1|h2|h3|h4|h5|h6|sub|sup|strike)[^><]*>/i', '', $string);
        $string = strip_tags($string);
        while(strpos($string, '  ')) {
            $string = str_replace('  ', ' ', $string);
        }
        $line = explode("\n", trim($string));
        $string = '';
        foreach($line as $row) {
            $row = trim($row);
            if(strlen($row) > 1) $string .= "\n$row";
        }
        return rtrim($string);

    }

    protected function replacePlus($find, $replace, $string) {

        error_reporting(0);
        $find = is_array($find) ? $find : array($find);
        $replace = is_array($replace) ? array_unshift($replace, false) : array_pad(array(false), count($find) + 1, $replace);

        foreach ($find as $row) {
            $key =mb_convert_encoding($row, "UTF-8", "GBK");// iconv( 'gbk//ignore','utf-8//ignore', $row);
            $val =mb_convert_encoding(next($replace), "UTF-8", "GBK");// iconv('gbk//ignore','utf-8//ignore', next($replace));
            if (strpos($string, $key) === false) continue;
            $string = str_replace($key, $val, $string);
        }
        return $string;
    }

    protected function splitword($string, $minwords, $maxwords) {
        $wordnum = $this->strlenPlus($string);
        if ($minwords > 0 && $wordnum <= $minwords) return false;
        if ($maxwords <= 0 || $this->strlenPlus($string) <= $maxwords) return $string;
        preg_match_all('/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/', $string, $match);
        return array_map('implode', array_chunk($match[0], $maxwords));
    }

    protected function strlenPlus($string) {
        if(function_exists('iconv_strlen')) return iconv_strlen($string, 'UTF-8');
        if(function_exists('mb_strlen')) return mb_strlen($string, 'UTF-8');
        preg_match_all('/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/', $string, $match);
        return count($match[0]);
    }

    public function textstr($str, $unclickable = false)
    {
        $from = array('　', '＂');
        $to = array(' ', '"');
        $str = str_replace($from, $to, $str);
        return $str;
    }
    /*****对于上传的小说文本进行格式化******/
    public function format_content($string) {
        //$string = strip_tags($string);
        $string = '<p>'.str_replace(array("'","''",'"',"　"," ","\r\n", "\r", "\n","<br/>"), array("”","”","“",'','',"</p><p>","</p><p>","</p><p>",''), $string)."</p>";
        return $string;

    }

    /**
     * Notes: 修改
     * @param $id
     * @return mixed|null
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     * @author: Zhu
     * @since: 2023/1/11 11:20
     */
    public function edit($id) {
        if (IS_POST) {
            //$result = $this->model->save($this->param, array('id'=> $id));
            $this->param["viptime"] = strtotime($this->param["viptime"]);
            $this->param["signtime"] = strtotime($this->param["signtime"]);
            $result = db('novel')->cache('bookinfo'.$id)->where('id',$id)->update($this->param);
            if ($result !== false) {
                //记录行为
                action_log('update_content', 'content', $result, session('user_auth.uid'));
                return $this->success("更新成功！", url('admin/novel/index', array('model_id' => $this->modelInfo['id'])));
            } else {
                return $this->error($this->model->getError(), url('admin/novel/edit', array('model_id' => $this->modelInfo['id'], 'id' => $id)));
            }
        } else {
            if (!$id) {
                return $this->error("非法操作！");
            }
            $info = $this->model->find($id);
            if (!$info) {
                return $this->error($this->model->getError());
            }
            $info['model_id'] = $this->modelInfo['id'];
            $data             = array(
                'info'       => $info,
                'fieldGroup' => $this->getField($this->modelInfo),
            );

            $this->assign($data);
            $this->setMeta("编辑" . $this->modelInfo['title']);
            return $this->fetch();
        }
    }
}